import {useEffect, useState} from "react";

function useLocalStorage(key) {
    const [data, setData] = useState(() => {
        return JSON.parse(localStorage.getItem(key))
    })
    if (!data) {
        setData('')
    }

    useEffect(() => {
        localStorage.setItem(key, JSON.stringify(data))
    }, [data]);

    return [data, setData]
}